package eu.news.data.hibernate.pojo;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import eu.news.data.pojo.News;
import eu.news.data.pojo.Operator;
import eu.news.data.pojo.Sort;
import eu.news.data.pojo.Special;

/**
 * 新闻分类
 * @author WZZ
 *
 */
@Entity
@Table(name="NewsSort",uniqueConstraints=@UniqueConstraint(columnNames={"name","special_id"}))
public class HB_Sort extends Sort implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6819617422752859106L;

	/**
	 * 代理主键
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	int id;
	
	/**
	 * 名称,not null
	 */
	@Column(name="name",length=100,nullable=false)
	String name;
	
	/**
	 * 新闻
	 */
	@OneToMany(cascade=CascadeType.ALL,mappedBy="sort",fetch=FetchType.LAZY)
	Set<HB_News> news=new HashSet<HB_News>();
	
	
	/**
	 * 专题
	 */
	@ManyToOne(cascade=CascadeType.ALL,
			targetEntity=HB_Special.class,
			fetch=FetchType.LAZY
		)
	@JoinColumn(name="special_id",nullable=false)
	HB_Special special;

	@ManyToMany(
	           cascade=CascadeType.ALL,
	           mappedBy="sorts"
	   )
	Set<HB_Operator> operators=new HashSet<HB_Operator>();
	
	public HB_Sort(){};

	public HB_Sort(String name, HB_Special special) {
		super();
		this.name = name;
		this.special = special;
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

	public Set<? extends News> getNews() {
		return news;
	}


	@SuppressWarnings("unchecked")
	public void setNews(Set<? extends News> news) {
		this.news = (Set<HB_News>) news;
	}


	public Special getSpecial() {
		return special;
	}


	public void setSpecial(Special special) {
		this.special = (HB_Special) special;
	}

	public Set<? extends Operator> getOperators() {
		return operators;
	}

	@SuppressWarnings("unchecked")
	public void setOperators(Set<? extends Operator> operators) {
		this.operators = (Set<HB_Operator>) operators;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HB_Sort other = (HB_Sort) obj;
		if (id != other.id)
			return false;
		return true;
	}

}
